﻿namespace SampleApp.Tests.Pages {
    using Microsoft.Services.TestTools.UITesting.Html;
    using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;

    [EntryUri("/Categories")]
    public class Categories : Page {

        public CategoriesCreate NavigateToCreateCategory() {
            Browser.ClickOnLink("Create New");
            return NavigatedTo<CategoriesCreate>();
        }

        public bool CategoryExistsInList(string categoryName) {
            var table = FindCategoriesTable();
            var cell = table.Find<HtmlControl>(new {InnerText = categoryName});

            return cell.Exists;
        }

        public bool CategoriesExists() {
            HtmlTable table = FindCategoriesTable();
            return table.RowCount > 1;
        }

        private HtmlTable FindCategoriesTable() {
            return Browser.Find<HtmlTable>(new { });
        }
    }
}
